package cn.hgpu.servlet;

import cn.hgpu.mapper.AdminMapper;
import cn.hgpu.utils.MybatisUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/delete")
public class AdminDeleteServlet extends HttpServlet {
    AdminMapper adminMapper = MybatisUtils.getMapper(AdminMapper.class);

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接收参数
       String id = req.getParameter("id");

       //逻辑处理
        adminMapper.deleteById(Integer.parseInt(id));
        MybatisUtils.commit();

        ////修改成功，跳转到查询servlet,经过其跳转到首页
        resp.sendRedirect("/admin/list");

    }
}
